package com.javaee.service.user.impl;

import com.javaee.entity.Record;
import com.javaee.mapper.user.URecordMapper;
import com.javaee.service.user.URecordService;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class URecordServiceImpl implements URecordService {
    @Autowired
    private URecordMapper uRecordMapper;
    @Override
    public List<Record> findByUserId(int pageNum, int pageSize, int uId) {
        return uRecordMapper.findByUserId(pageNum,pageSize,uId);
    }

    @Override
    public int selectCount(int uId) {
        return uRecordMapper.selectCount(uId);
    }

    @Override
    public Record findARecordById(int id) {
        return uRecordMapper.findARecordById(id);
    }

    @Override
    public String convertMarkdownToHtml(String markdownContent) {
        Parser parser = Parser.builder().build();
        Node document = parser.parse(markdownContent);
        HtmlRenderer renderer = HtmlRenderer.builder().build();
        return renderer.render(document);
    }
}
